import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class ThreadExample extends Thread{

	public void run() {

		Statement stmt;
		ResultSet res ;
		try
		{
			String endString = GLOBAL.selectionPanel.textBoxArtist.text.substring(0,GLOBAL.selectionPanel.textBoxArtist.text.length()-1);
			Character c = GLOBAL.selectionPanel.textBoxArtist.text.charAt(GLOBAL.selectionPanel.textBoxArtist.text.length()-1);
			c = new Character((char) (c.charValue()+1));
			//System.out.println(c); System.out.println(endString);
			endString = endString.concat(c.toString());
			
			String sql = "SELECT DISTINCT artist_name,mb_code FROM artists WHERE artist_name >= '"+
					GLOBAL.selectionPanel.textBoxArtist.text.replace("'", "''")+"' AND artist_name < '"+endString.replace("'", "''")+"' LIMIT 50";
			stmt = GLOBAL.user_db_con.createStatement();
			res = stmt.executeQuery(sql);

		}
		catch(SQLException e)
		{
			System.out.println("Error creating or running statement: " + e.toString());
			return;
		}



		try
		{
			String artistName;
			String artistId;
			while(res.next())
			{
				artistName = res.getString("artist_name");
				artistId = res.getString("mb_code");
				//TODO change this
				Artist artist = new Artist(artistId,artistName);
				GLOBAL.selectionPanel.textBoxArtist.suggestionButtonsToShow.add(
						new ButtonArtist(artistName,GLOBAL.selectionPanel.textBoxArtist.x+5,0,artist));

			}
		}
		catch(Exception e)
		{
			System.out.println("Error processing results: " + e.toString());
			try
			{
				res.close();
				stmt.close();
			}
			catch(Exception ex){}
			return;
		}

	}


}
